/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.item.etcitem.action;

import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.item.ItemExecutor;
import com.lineage.server.model.skill.L1SkillUse;
import com.lineage.server.packetserver.S_ServerMessage;

/**
 * Class <code>MagicScrollLong</code> 魔法卷轴 - Long. <br>
 * 40862 - 魔法卷轴 (光箭) <br>
 * 40864 - 魔法卷轴 (冰箭) <br>
 * 40865 - 魔法卷轴 (风刃) <br>
 * 40869 - 魔法卷轴 (毒咒) <br>
 * 40873 - 魔法卷轴 (火箭) <br>
 * 40874 - 魔法卷轴 (地狱之牙) <br>
 * 40875 - 魔法卷轴 (极光雷电) <br>
 * 40876 - 魔法卷轴 (起死回生术) <br>
 * 40878 - 魔法卷轴 (闇盲咒术) <br>
 * 40880 - 魔法卷轴 (寒冰气息) <br>
 * 40881 - 魔法卷轴 (能量感测) <br>
 * 40883 - 魔法卷轴 (燃烧的火球) <br>
 * 40885 - 魔法卷轴 (坏物术) <br>
 * 40887 - 魔法卷轴 (缓速术) <br>
 * 40888 - 魔法卷轴 (岩牢) <br>
 * 40891 - 魔法卷轴 (木乃伊的诅咒) <br>
 * 40892 - 魔法卷轴 (极道落雷) <br>
 * 40894 - 魔法卷轴 (迷魅术) <br>
 * 40896 - 魔法卷轴 (冰锥) <br>
 * 40898 - 魔法卷轴 (黑闇之影) <br>
 * 
 * @author jrwz
 * @version 2012-6-19下午14:43:10
 * @see com.lineage.server.model.item.etcitem.action
 * @since JDK1.7
 */
public final class MagicScrollLong extends ItemExecutor {

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static ItemExecutor get() {
        return new MagicScrollLong();
    }

    /** 魔法卷轴 - Long. */
    private MagicScrollLong() {
    }

    @Override
    public void execute(final L1PcInstance pc, final L1ItemInstance useItem,
            final int readC1, final int readC2, final int targetId,
            final int targetX, final int targetY) {

        // 隐身状态不可用
        if (pc.isInvisble() || pc.isInvisDelay()) {
            pc.sendPackets(new S_ServerMessage(281)); // \f1施咒取消。
            return;
        }

        final int targetID = targetId;
        final int spellscX = targetX;
        final int spellscY = targetY;

        // 目标为自己或空
        if ((targetID == pc.getId()) || (targetID == 0)) {
            pc.sendPackets(new S_ServerMessage(281)); // \f1施咒取消。
            return;
        }

        final int useCount = 1;
        if (pc.getInventory().removeItem(useItem, useCount) >= useCount) {
            final int itemId = useItem.getItemId();
            final int skillid = itemId - 40858;
            final L1SkillUse l1skilluse = new L1SkillUse();
            l1skilluse.handleCommands(pc, skillid, targetID, spellscX,
                    spellscY, null, 0, L1SkillUse.TYPE_SPELLSC);
        }
    }
}
